<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>险种管理</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="css/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="js/demo.css">
		<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
		<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/usedcar.css">
		<style type="text/css">
		#main {
			width: 100%;
		}
		</style>
		<script type="text/javascript"> 
			function init(){
    			if("${message}"!=""){
					alert("${message}");
				}
    		}
		</script>
	</head>
  <body  onload="init();">
<div id="main">
	<table id="dg" title="险种信息" class="easyui-datagrid" style="width:1150px;height:560px"  
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">   
    </table>  
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新建</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>  
    </div>  
      
    <div id="dlg" class="easyui-dialog" style="width:400px;height:350px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <form id="fm" method="post">  
            <table>  
                <tr>  
                    <td></td>  
                    <td><input class="easyui-validatebox" type="hidden" id="id" name="id" readonly="readonly"></input></td>  
                </tr>  
                <tr>  
                    <td></td>  
                    <td><input class="easyui-validatebox" type="hidden" id="createtime" name="createtime" readonly="readonly"></input></td>  
                </tr>  
                <tr>  
                    <td>险种编号：</td>  
                    <td><input class="easyui-validatebox" type="text" id="idType" name="idType" ></input></td>  
                </tr>  
                <tr>  
                    <td>公司编号:</td>  
                	<td><select class="easyui-combogrid" id="idCompany" name="idCompany" style="width:134px" data-options="  
                    			required:true,
                    			missingMessage:'此项必填',
					            panelWidth: 200,  
					            idField: 'idCompany',  
					            textField: 'companyname',    
					            columns: [[  
					                {field:'idCompany',title:'公司编号',hidden:true},  
					                {field:'companyname',title:'公司名称',width:120,align:'left'} 
					            ]],
					            loader:function(param, success, error) {
					            	success(${carInsuranceCom});
					            },  
					            fitColumns: true  
					        ">  
					    </select> 
				    </td>  
                </tr>  
                <tr>  
                    <td>险种名称:</td>  
                    <td><input class="easyui-validatebox" type="text" id="typename" name="typename"></input></td>  
                </tr>  
                <tr>  
                    <td>理赔率:</td>  
                    <td><input class="easyui-validatebox" type="text" id="bedding" name="bedding" ></input></td>  
                </tr>  
            </table>  
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
    </div>  
    <script type="text/javascript">  
 		$('#dg').datagrid({ 
			remoteSort : false,
			pageSize: 10,  	
			pageList: [15, 20, 30, 50],
			loadFilter: pagerFilter,
			columns:[[  
			          {field:'idType',title:'险种编号',width:80,align:'center', sortable:'true'} ,
			          {field:'idCompany',title:'保险公司编号',width:80,align:'center', sortable:'true',
			           formatter:function(value,row){
								var companys = ${carInsuranceCom};
								for(var i=0;i<companys.length;i++){
									if(row.idCompany == companys[i].idCompany){
										return companys[i].companyname;
									}
								}
			        	  }},   
			          {field:'typename',title:'险种名称',width:80,align:'center', sortable:'true'} ,
			          {field:'bedding',title:'理赔率',width:80,align:'center', sortable:'true'} ,
			          {field:'createtime',title:'创建时间',width:80,align:'center', sortable:'true',
			           formatter:function(value,row){
								var str = row.createtime;
								if(str==null){
									return "";
								}else{
									var m = str.month+1;
									var d = str.date;
									return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
								}
			        	  }},  
			          {field:'updatetime',title:'修改时间',width:80,align:'center', sortable:'true',
			           formatter:function(value,row){
								var str = row.updatetime;
								if(str==null){
									return "";
								}else{
									var m = str.month+1;
									var d = str.date;
									return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
								}
			        	  }}
			]],
 			loader: function(param, success, error) {
	 			success(${carType});
	 		}
 		}); 
 		$('#dg').datagrid('selectRow',3);
 		function pagerFilter(data){
			if ($.isArray(data)){	// is array
					data = {
						total: data.length,
						rows: data
					}
			}
			var dg = $('#dg');
			var opts = dg.datagrid('options');
			var pager = dg.datagrid('getPager');
			pager.pagination({
				onSelectPage:function(pageNum, pageSize){
					opts.pageNumber = pageNum;
					opts.pageSize = pageSize;
					pager.pagination('refresh',{
						pageNumber:pageNum,
						pageSize:pageSize
					});
					dg.datagrid('loadData',data);
				},
				onRefresh:function(pageNumber, pageSize){
					dg.datagrid('reload');
				}
			});
			if (!data.originalRows){
				data.originalRows = (data.rows);
			}
			var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
			var end = start + parseInt(opts.pageSize);
			data.rows = (data.originalRows.slice(start, end));
			return data;
		}
		 function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','险种');  
            $('#fm').form('clear');
	        document.getElementById('fm').action="/aasimp/mok/insurance/insur_addtype_hou";  
        }  
        function editUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $('#dlg').dialog('open').dialog('setTitle','修改险种');  
                $('#idType').val(row.idType);
                $('#idCompany').combogrid('setValue', row.idCompany);
                $('#typename').val(row.typename);
                $('#bedding').val(row.bedding);
                $('#createtime').val(formatDate(row.createtime));
	        	document.getElementById('fm').action='/aasimp/mok/insurance/insur_updatetype_hou?id='+row.id; 
            }  
        }
         function saveUser(){
        	if($('#fm').form('validate')){
	            $('#fm').submit();
	            $('#dlg').dialog('close');
        	}   
        }
        function formatDate(str){
			var m = str.month+1;
			var d = str.date;
        	return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
        }  
        function destroyUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $.messager.confirm('提示','确定删除这条记录吗?',function(r){  
                    if (r){
                      	window.location = '/aasimp/mok/insurance/insur_deletetype?id='+row.id+"&idType="+row.idType;
                    }  
                });  
            }  
        }  
    </script>  
    <style type="text/css">  
        #fm{  
            margin:0;  
            padding:10px 30px;  
        }  
        .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:10px;  
            border-bottom:1px solid #ccc;  
        }  
        .fitem{  
            margin-bottom:5px;  
        }  
        .fitem label{  
            display:inline-block;  
            width:80px;  
        }
    </style>
</div>


  </body>
</html>
